<template>
  <div style="width: 300px; margin-right: 20px;">
    <partial-view v-ref:pv @condition-changed="selfSearch">
      <criteria-paged :model="model" v-ref:paged :pager="false">
        <criteria partial='criteria' v-ref:criteria>
          <div novalidate class="flex-row" partial>
            <div class="form-group" style="flex: 1;">
              <input type="text" class="form-control" v-model="model.f_area_address"
              condition="f_area_address like '%{}%'" placeholder='小区地址'>
            </div>
            <div class="form-group" style="margin-right: 0px;" id='filesArea'>
              <button class="btn btn-success width-100" @click="search()">查询</button>
            </div>
          </div>
        </criteria>
        <data-grid :model="model" partial='list' v-ref:grid >
          <template partial='head'>
          <tr>
            <th>序号</th>
            <th>小区详细地址</th>
            <th>操作</th>
          </tr>
          </template>
          <template partial='body'>
            <td id = "1" style="text-align: center;">{{$index + 1}}</td>
            <td>{{row.f_area_address}}</td>
            <td style="text-align: center;">
              <button type="button" name="button" class="btn btn-link" @click.stop="$parent.$parent.$parent.$parent.foundFile(row)">建档</button>
            </td>
          </template>
        </data-grid>
       </criteria-paged>
     </partial-view>
  </div>
</template>

<script>
import { PagedList } from 'vue-client'
import * as Util from '../Util'

export default {
  title: '小区列表',
  data () {
    return {
      model: new PagedList('rs/sql/getArea', 500, {orderitem: '"a.id desc"'})
    }
  },
  ready () {
    this.search({condition: '1=1'})
  },
  methods: {
    foundFile (row) {
      this.$dispatch('bulid-files', '小区批量建档', row)
    },
    search (obj) {
      console.log('查询  search')
      if (!Util.f.parent.parent.name.includes('统一资源管理')) {
        obj.condition += ` and a.f_filiale = '${Util.f.f_fengongsi}'`
      }
      // this.$refs.paged.$refs.criteria.search()
      this.$refs.pv.load('rs/sql/getArea', {data: {
        orderitem: 'a.id',
        condition: obj.condition
      }}).then((a) => {
        if (a.data.length === 0) {
          this.model.state = '错误'
          this.model.error = '没有相关的小区信息'
          return
        }
        this.model.state = '正确'
        this.model.rows = a.data
      })
    },
    selfSearch (datas) {
      console.log('查询  selfsearch')
      if (!Util.f.parent.parent.name.includes('统一资源管理')) {
        datas.condition += ` and a.f_filiale = '${Util.f.f_fengongsi}'`
      }
      this.model.search(datas.condition, this.model)
    },
    // 主要提供外部组件调用，刷新数据
    reflash () {
      this.$refs.paged.$refs.criteria.search()
    }
  }
}
</script>
